<table id="dg-user" style="height:100%;width: 100%;">
    <thead>
    <tr>
        <th data-options="field:'USER_GH',width:100">工号</th>
        <th data-options="field:'USER_NAME',width:100">用户名</th>
        <th data-options="field:'USER_XM',width:100">姓名</th>
        <th data-options="field:'USER_ROLE',width:100">角色</th>
        <th data-options="field:'USER_PHONE',width:100">手机号码</th>
        <th data-options="field:'USER_EMAIL',width:100">邮箱地址</th>
        <th data-options="field:'LRSJ',formatter:DateTimeFormatter,width:100">创建日期</th>
    </tr>
    </thead>
</table>

<div id="tb-user">
    <table cellpadding="0" cellspacing="0" style="width:100%">
        <tr class="clearfix">
            <td class="luck-tool-button">
                姓名: <input class="easyui-textbox" name="dg_user_xm" id="dg_user_xm" style="width:200px">
                工号: <input class="easyui-textbox" name="dg_user_gh" id="dg_user_gh" style="width:200px">
                <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="user_tool.search();">${i18n('btn.search')}</a>
            </td>
            <td class="luck-tool-button luck-text-right luck-right">
                <a href="#" class="easyui-linkbutton button-blue" plain="true" onclick="user_tool.add();"><i class="fa fa-plus fa-lg"></i>&nbsp;${i18n('btn.new')}</a>
                <a href="#" class="easyui-linkbutton button-teal" plain="true" onclick="user_tool.edit();"><i class="fa fa-edit fa-lg"></i>&nbsp;${i18n('btn.edit')}</a>
                <a href="#" class="easyui-linkbutton button-purple" plain="true" onclick="user_tool.initpwd();"><i class="fa fa-key fa-lg"></i>&nbsp;${i18n('btn.initpwd')}</a>
                <a href="#" class="easyui-linkbutton button-red" plain="true" onclick="user_tool.delete();"><i class="fa fa-close fa-lg"></i>&nbsp;${i18n('btn.delete')}</a>
            </td>
        </tr>
    </table>
</div>
<script>
    var dg_user;
    $(function () {
        dg_user = rsdp.createDataGrid({
            tid: "dg-user",
            url: "${ctxPath}/system/user/manage",
            idField: "user_id",
            loadMsg: "${i18n('oper.loading')}",
            tbid: "tb-user"
        });
    });

    var user_tool = {
        add: function () {
            rsdp.createDialog({
                url: "${ctxPath}/system/user/add",
                title: "${i18n('msg.user.new')}",
                width: 500,
                height: 500,
                btnArray: [{
                    cls: 'easyui-linkbutton button-blue',
                    iconCls: 'fa fa-check fa-lg',
                    text: "${i18n('btn.save')}",
                    handler: function () {
                        user_tool.add_save();
                    }
                },
                    {
                        iconCls: 'fa fa-close fa-lg',
                        text: "${i18n('btn.close')}",
                        handler: function () {
                            rsdp.closeDialog();
                        }
                    }]
            });
            //清除关闭数据没清空问题
            $("#form-add").form('clear');
        },
        add_save: function () {
            rsdp.ajaxform({
                fid: "form-add",
                url: "${ctxPath}/system/user/addSave",
                func: function () {
                    rsdp.closeDialog();
                    dg_user.datagrid("reload");
                    dg_user.datagrid("clearSelections");
                }
            });
        },
        edit: function () {
            var row = getSelectRow('#dg-user');
            if (row) {
                rsdp.createDialog({
                    url: "${ctxPath}/system/user/edit",
                    title: "${i18n('msg.user.edit')}",
                    width: 500,
                    height: 500,
                    param: {id: row.USER_ID},
                    btnArray: [{
                        cls: 'easyui-linkbutton button-blue',
                        iconCls: 'fa fa-check fa-lg',
                        text: "${i18n('btn.save')}",
                        handler: function () {
                            user_tool.edit_save();
                        }
                    },
                        {
                            iconCls: 'fa fa-close fa-lg',
                            text: "${i18n('btn.close')}",
                            handler: function () {
                                rsdp.closeDialog();
                            }
                        }]
                });
            }
            else {
                //layer.msg("${i18n('msg.row.select')}", {time: 1000});
                rsdp.msg("${i18n('msg.row.select')}", {time: 1000});
            }
        },
        edit_save: function () {
            rsdp.ajaxform({
                fid: "form-edit",
                url: "${ctxPath}/system/user/editSave",
                func: function () {
                    rsdp.closeDialog();
                    dg_user.datagrid("reload");
                    dg_user.datagrid("clearSelections");
                }
            });
        },
        refresh: function () {
            rsdp.refresh();
        },
        search: function () {
            dg_user.datagrid('load', {
                userxm: $('#dg_user_xm').val(),
                usergh: $('#dg_user_gh').val()
            });
            dg_user.datagrid("clearSelections");
        },
        delete: function () {
            var row = getSelectRow('#dg-user');
            //console.log(row);
            if (row) {
                rsdp.ajaxPostJson({
                    url: "${ctxPath}/system/user/delete",
                    param: {"id": row.USER_ID},
                    cstr: "${i18n('msg.row.delete')}",
                    func: function () {
                        dg_user.datagrid("reload");
                        dg_user.datagrid("clearSelections");
                    }
                });
            }
            else {
                //layer.msg("${i18n('msg.row.select')}", {time: 1000});
                rsdp.msg("${i18n('msg.row.select')}", {time: 1000});
            }
        },
        initpwd: function () {
            var row = getSelectRow('#dg-user');
            //console.log(row);
            if (row) {
                rsdp.ajaxPostJson({
                    url: "${ctxPath}/system/user/initPwd",
                    param: {"id": row.USER_ID},
                    cstr: "${i18n('msg.pass.init')}"
                });
            }
            else {
                //layer.msg("${i18n('msg.row.select')}", {time: 1000});
                rsdp.msg("${i18n('msg.row.select')}", {time: 1000});
            }
        }

    }
</script>